<?php

ini_set('display_errors', 1);
define('IMPL', dirname(__FILE__) . "/modules/impl");
define('MODULES', dirname(__FILE__) . "/modules");
define('PORTLETS', dirname(__FILE__) . "/portlets");
define('PORTLETS_IMPL', dirname(__FILE__) . "/portlets/impl");
define('BO_LIBS', dirname(__FILE__) . "/bo");
define('RELATIVE_PATH', "");
define('CORE_PATH', 'main.php');
define('AJAX_INDICATOR', 'ajax');
define('FORM_NAME', md5('easoftwareform'));
define('SITE_PATH', '/ReportingWebSercogua/');
define('IMAGES', dirname(__FILE__) . "/uploads/");
define('LOGO_PATH', "sercogualogo.png");
define('PATH_UPLOAD_GENERAL', dirname(__FILE__) . "/uploadingservice/uploads/");
define('MODULES_DB', '????mODULES????');
define('PORTLETS_DB', '????pORTLETS????');
define('APPWRAPPER', '????aPPwRAPPER????');
define('CFG_REPORTES', "reportes/impl");

// parametros aplicacion
define('APP_TITLE', "Ea-App-Template");
define('APP_LOGO', "Ea-App-Template");

include "include/functions.inc.php";
include "include/excel.class.php";
include "include/mysql_excel.inc.php";
include "include/pdf/config/lang/spa.php";
include "include/pdf/tcpdf.php";
include "include/widget.inc.php";
include "include/inputbuilder.inc.php";
include "include/easoftmodule.inc.php";
include "include/easoftportlet.inc.php";
include "include/easoftprinter.php";
include "include/EaExcelPrinter.php";
include "include/EaPdfPrinter.php";
include "include/easoftiframemodule.inc.php";
include "include/maintenance.inc.php";
include "include/fastmaintenance.inc.php";
include "include/complexmaintenance.inc.php";
include "include/jgridgenerator.class.php";
include "include/upload.class.php";
include "include/imagereader.php";
include "include/thumbnail_generator.php";
include "include/PortletFactory.php";
include "include/easoftwarebussinesobject.php";
include "include/eareportdoc.php";
include 'include/phpmailer.inc.php';
include "include/smtp.inc.php";

includeModules(IMPL);
includeModules(BO_LIBS);
$boSec = BoSecurity::getMe();
if (!isEmpty(getParam("action"))) {
    $boSec->registrarAccion("Salir del sistema!", "Ha solicitado salir del sistema");
    header('Location: logout.php');
}
$modName = getParam("module");
$module = NULL;
$modules = array();

if (isset($_SESSION[MODULES_DB])) {
    $modules = unserialize($_SESSION[MODULES_DB]);
}

if (isset($modules[$modName])) {
    $module = $modules[$modName];
} elseif (!isEmpty($modName)) {
    $module = new $modName();
    if ($module->includePath) {
        $module->includePath = MODULES . DS . $module->includePath;
    }
}


if (!defined("LINKS_PATH") && $module != null) {
    define("LINKS_PATH", CORE_PATH . "?" . AJAX_INDICATOR . "=true&module=" . $module->instanceName);
}
$sec = new AppSecurity();
$sec->isLogged();
if (isEmpty(getParam(AJAX_INDICATOR))) {
    if (!isset($_SESSION["appwrap"])) {
        $appWrap = new AppWrapper();
    } else {
        $appWrap = unserialize($_SESSION["appwrap"]);
        echo "3";
    }
    if ($module != NULL) {
        $appWrap->module = $module;
    }
    $appWrap->db = DbManager::getMe();
    $appWrap->main();
    $_SESSION[APPWRAPPER] = serialize($appWrap);
} else {

    $module->db = DbManager::getMe();
    $module->main();
}
if (!isEmpty(getParam("meac"))) {
    $boSec->registrarAccion("Acceso Opcion Menu", "Ha ingresado al modulo del sistema llamado: $modName");
}
$modules[$modName] = $module;
$_SESSION[MODULES_DB] = serialize($modules);
?>